package com.ssy.lingxi.member.merchant.model.bo;

import com.fasterxml.jackson.annotation.JsonProperty;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * 省市区域数据库保存BO
 * @author 万宁
 * @version 2.0.0
 * @date 2020-08-26
 */
public class AgentAreaBO implements Serializable {
    private static final long serialVersionUID = 6581405015632952935L;

    public AgentAreaBO() {
        this.upperRelationId = 0L;
        this.areas = new ArrayList<>();
    }

    public AgentAreaBO(Long upperRelationId, String provinceCode, String province, String cityCode, String city) {
        this.upperRelationId = upperRelationId;
        this.areas = Stream.of(new AreaBO(provinceCode, province, cityCode, city)).collect(Collectors.toList());
    }

    public AgentAreaBO(Long upperRelationId, List<AreaBO> areas) {
        this.upperRelationId = upperRelationId;
        this.areas = areas;
    }

    /**
     * 上级渠道会员关系Id
     */
    @JsonProperty("r")
    private Long upperRelationId;

    @JsonProperty("a")
    List<AreaBO> areas;

    public Long getUpperRelationId() {
        return upperRelationId;
    }

    public void setUpperRelationId(Long upperRelationId) {
        this.upperRelationId = upperRelationId;
    }

    public List<AreaBO> getAreas() {
        return areas;
    }

    public void setAreas(List<AreaBO> areas) {
        this.areas = areas;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        AgentAreaBO that = (AgentAreaBO) o;
        return Objects.equals(upperRelationId, that.upperRelationId) &&
                Objects.equals(areas, that.areas);
    }

    @Override
    public int hashCode() {
        return Objects.hash(upperRelationId, areas);
    }
}
